package com.miao.teacher.ui;
import com.miao.teacher.adapter.MenuAdapter;
import com.miao.teacher.presenters.OnMenuSelectListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class MenuFragment extends Fragment {

	private OnMenuSelectListener mCallBack;
	private ListView lv;
	private MenuAdapter mAdapter;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.frame_menu_layout, null);
		lv=(ListView)view.findViewById(R.id.lv);
		mAdapter=new MenuAdapter(getActivity());
		lv.setAdapter(mAdapter);
		lv.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				mAdapter.setIndex(arg2);
				mAdapter.notifyDataSetChanged();
				mCallBack.OnMenuSelected(arg2);
			}
			
		});
		return view;
	}
	public void setSelectIndex(int index)
	{
		mAdapter.setIndex(index);
		mAdapter.notifyDataSetChanged();
	}
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		try {
			mCallBack = (OnMenuSelectListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnMenuSelectListener");
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
}
